<controls:ChildWindow  
    x:Class="ibba.src.noriskbo.views.childs.ChildGarantia"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:slc="clr-namespace:ibba.src.sl.componentes;assembly=ibba.src.sl.componentes"
    xmlns:resv="clr-namespace:ibba.src.sl.recursos.Validations;assembly=ibba.src.sl.recursos"
    xmlns:vm="clr-namespace:ibba.src.noriskbo.ViewModels"    
    Width="Auto" Height="Auto"
    Title="Garantia Manual"
    Style="{StaticResource ChildWindowStyle}">

    <controls:ChildWindow.Resources>
        <vm:ChildGarantiaViewModel x:Key="viewModel" />
    </controls:ChildWindow.Resources>

    <Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource viewModel}}">
        <toolkit:BusyIndicator IsBusy="{Binding IsBusy}" BusyContent="{Binding BusyText}">

            <Grid x:Name="gridDados">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="85" />
                </Grid.RowDefinitions>

                <resv:ValidationManager x:Name="validatorManager" />

                <slc:ControlMenuBar x:Name="barraMenu" Grid.Row="3" VisibilityUserPanel="Collapsed" 
                                    BorderRadius="15,0,15,0" Background="{StaticResource BlueStrong}"/>

                <Border Grid.Row="0" CornerRadius="10,0,0,0" BorderThickness="1" BorderBrush="#FF5A7194" Background="#FFE7E9EC" Padding="3">
                    <StackPanel Orientation="Horizontal">
                        <TextBlock FontSize="12" Width="470">
                            <Run Text="Grupo: " FontWeight="Bold"/>
                            <Run Text="{Binding Path=Entidade.IdGrupo}"/>
                            <Run Text=" - "/>
                            <Run Text="{Binding Path=Entidade.NomeGrupo}"/>
                        </TextBlock>

                        <TextBlock FontSize="12" Margin="10,0,0,0" MinWidth="150">
                            <Run Text="Origem: " FontWeight="Bold"/>
                            <Run Text="{Binding Path=Entidade.DescricaoOrigem}"/>
                        </TextBlock>

                        <TextBlock FontSize="12" Margin="10,0,0,0" MinWidth="200">
                            <Run Text="Status: " FontWeight="Bold" />
                            <Run Text="{Binding Path=Entidade.DescricaoStatus}"/>
                        </TextBlock>
                    </StackPanel>
                </Border>

                <Border CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="#FF5A7194" Background="White" Margin="0,2,0,-12" Padding="2" Grid.Row="2">
                    <StackPanel Orientation="Vertical">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Incluído por:" VerticalAlignment="Center" FontWeight="Bold" Width="80" Margin="5,0,0,0" />
                            <TextBlock x:Name="lblUsuarioIncluiu" Text="{Binding Path=Entidade.DetalheGarantia.UsuarioIncluiu}" VerticalAlignment="Center" Margin="5,0,0,0" MinWidth="400" />
                            <TextBlock x:Name="lblDataInclusao" Text="{Binding Path=Entidade.DetalheGarantia.DataInclusao, Converter={StaticResource DateTimeConverter}}" VerticalAlignment="Center" Margin="5,0,0,0"/>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Alterado por:" VerticalAlignment="Center" FontWeight="Bold" Width="80" Margin="5,0,0,0" />
                            <TextBlock x:Name="lblUsuarioAlterou" Text="{Binding Path=Entidade.DetalheGarantia.UsuarioAlterou}" VerticalAlignment="Center" Margin="5,0,0,0" MinWidth="400" />
                            <TextBlock x:Name="lblDataAlteracao" Text="{Binding Path=Entidade.DetalheGarantia.DataAlteracao, Converter={StaticResource DateTimeConverter}}" VerticalAlignment="Center" Margin="5,0,0,0"/>
                        </StackPanel>
                    </StackPanel>
                </Border>

                <ContentControl Grid.Row="1"
                                IsEnabled="{Binding StateView}">
                    <Grid Grid.Row="1" Margin="0,8,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Orientation="Vertical" Grid.Row="1" Grid.Column="0" >
                            <Border CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="#FF5A7194" Background="WhiteSmoke" Margin="0,2">
                                <StackPanel Orientation="Vertical">
                                    <Grid Background="White" HorizontalAlignment="Left" Margin="10,-8,0,2">
                                        <TextBlock Text="Chave do Contrato/Garantia" FontSize="11" Margin="5,0"/>
                                    </Grid>

                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Contrato" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <TextBox Width="200" MaxLength="20" Text="{Binding Path=Entidade.CodigoContrato}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Cliente" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <sdk:AutoCompleteBox Width="200" IsTextCompletionEnabled="True"
                                                         ItemsSource="{Binding ListClientes}"
                                                         SelectedItem="{Binding SelectedCliente, Mode=TwoWay}"
                                                         ValueMemberPath="IdCliente"
                                                         ItemTemplate="{StaticResource DataTemplateCliente}"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Produto" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <sdk:AutoCompleteBox Width="200" IsTextCompletionEnabled="True"
                                                         ItemsSource="{Binding Path=ListaProdutos}"
                                                         SelectedItem="{Binding Path=ProdutoSelecionado, Mode=TwoWay}"
                                                         ValueMemberPath="cd_Produto"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Modalidade" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <ComboBox Width="200" 
                                              ItemsSource="{Binding Path=ListaModalidades}"
                                              SelectedValue="{Binding Path=Entidade.IdProdutoRisco, Mode=TwoWay}"
                                              SelectedValuePath="idProduto" DisplayMemberPath="cd_Modalidade"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Nº Garantia" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <TextBox Width="200" MaxLength="10" resv:TextBoxFilterService.Filter="Integer"
                                             Text="{Binding Path=Entidade.NumeroGarantia, Mode=TwoWay}"/>
                                    </StackPanel>

                                    <Border Margin="0,2,0,0" CornerRadius="0,0,5,5" Background="#DEE5E5E5">
                                        <TextBlock Name="txtDuplicidade" FontSize="11" Height="15" 
                                               HorizontalAlignment="Stretch" Foreground="#FFE13511" TextAlignment="Center" 
                                               Text="{Binding Path=Entidade.ResultVerificacaoDuplicidade}"/>
                                    </Border>
                                </StackPanel>
                            </Border>

                            <Border CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="#FF5A7194" Background="White" Margin="0,2">
                                <StackPanel Orientation="Vertical">
                                    <StackPanel Orientation="Horizontal" Margin="5,5,5,1">
                                        <TextBlock Text="Instrumento" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <ComboBox Width="200" 
                                              ItemsSource="{Binding Path=ListaInstrumentos}"
                                              SelectedItem="{Binding Path=InstrumentoSelecionado, Mode=TwoWay}">
                                            <ComboBox.ItemTemplate>
                                                <DataTemplate>
                                                    <StackPanel Orientation="Vertical" Margin="0,2">
                                                        <TextBlock Text="{Binding Path=Descricao}" />
                                                        <TextBlock FontSize="9">
                                                        <Run Text="Transfere Risco: "/>
                                                        <Run Text="{Binding Path=TransfereRisco, Converter={StaticResource SimNaoConverter}}" Foreground="Blue"/>
                                                        </TextBlock>
                                                    </StackPanel>
                                                </DataTemplate>
                                            </ComboBox.ItemTemplate>
                                        </ComboBox>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Bem" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <ComboBox Width="200" 
                                              ItemsSource="{Binding Path=ListaBens}"
                                              SelectedItem="{Binding Path=BemSelecionado, Mode=TwoWay}"
                                              DisplayMemberPath="DescricaoBem"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Natureza" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <ComboBox Width="200" 
                                              ItemsSource="{Binding Path=ListaNaturezas}"
                                              SelectedItem="{Binding Path=NaturezaSelecionado, Mode=TwoWay}">
                                            <ComboBox.ItemTemplate>
                                                <DataTemplate>
                                                    <StackPanel Orientation="Vertical" Margin="0,2">
                                                        <TextBlock Text="{Binding Path=DescricaoNatureza}" />
                                                        <TextBlock Text="{Binding Path=Qualidade, StringFormat=0%}" FontSize="9" Foreground="Blue" />
                                                    </StackPanel>
                                                </DataTemplate>
                                            </ComboBox.ItemTemplate>
                                        </ComboBox>
                                    </StackPanel>

                                    <Border Margin="0,2,0,0" CornerRadius="0,0,5,5" Background="WhiteSmoke">
                                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                                            <TextBlock FontSize="10" HorizontalAlignment="Left" Margin="0,0,10,0">
                                                <Run Text="Qualidade da Trinca: " />
                                                <Run Text="{Binding Path=BemSelecionado.Qualidade, StringFormat=0%, FallbackValue='100%'}" Foreground="#FF1557EB" />
                                            </TextBlock>                                            
                                            <TextBlock FontSize="10" HorizontalAlignment="Left" Margin="0,0,10,0">
                                                <Run Text="Transfere Risco: " />
                                                <Run Text="{Binding Path=InstrumentoSelecionado.TransfereRisco, Converter={StaticResource SimNaoConverter}, FallbackValue='Não'}" Foreground="#FF1557EB" />
                                            </TextBlock>                                            
                                        </StackPanel>
                                    </Border>
                                </StackPanel>
                            </Border>

                            <Border CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="#FF5A7194" Background="White" Margin="0,2">
                                <StackPanel Orientation="Vertical">
                                    <StackPanel Orientation="Horizontal" Margin="5,5,5,1">
                                        <TextBlock Text="Moeda" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <sdk:AutoCompleteBox Width="130" 
                                                         ItemsSource="{Binding Path=ListaMoedas}"
                                                         SelectedItem="{Binding Path=MoedaSelecionada, Mode=TwoWay}"
                                                         ValueMemberPath="cd_moeda"
                                                         ItemTemplate="{StaticResource DataTemplateMoeda}"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,-2,5,1">
                                        <TextBlock FontSize="9" FontWeight="Bold" Margin="105,0,0,0">
                                        <Run Text="Cotação D-1: " />
                                        <Run Text="{Binding Path=MoedaSelecionada.ValorCotacao}" Foreground="#FFCEA215" />
                                        </TextBlock>
                                    </StackPanel>

                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Valor Original" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <TextBox Width="130" MaxLength="15" TextAlignment="Right" resv:TextBoxFilterService.Filter="Decimal" 
                                             Text="{Binding Path=Entidade.DetalheGarantia.ValorOriginalMoeda, Mode=TwoWay, Converter={StaticResource DecimalConverter}}"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,-2,5,1">
                                        <TextBlock FontSize="9" FontWeight="Bold" Margin="105,0,0,0">
                                        <Run Text="BRL: " />
                                        <Run Text="{Binding Path=ValorOriginalBRL}" Foreground="#FFCEA215" />
                                        </TextBlock>
                                    </StackPanel>

                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Valor Atualizado" FontWeight="Bold" Width="105" VerticalAlignment="Center"/>
                                        <TextBox Width="130" MaxLength="15" TextAlignment="Right" resv:TextBoxFilterService.Filter="Decimal" 
                                             Text="{Binding Path=Entidade.ValorAtualizado, Mode=TwoWay, Converter={StaticResource DecimalConverter}}"/>
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,-2,5,1">
                                        <TextBlock FontSize="9" FontWeight="Bold" Margin="105,0,0,0">
                                        <Run Text="BRL: " />
                                        <Run Text="{Binding Path=ValorAtualizadoBRL}" Foreground="#FFCEA215" />
                                        </TextBlock>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                        </StackPanel>

                        <StackPanel Orientation="Vertical" Grid.Row="1" Grid.Column="1" Margin="5,0,0,0">
                            <Border CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="#FF5A7194" Background="White" Margin="0,2,0,8" Padding="0,3">
                                <StackPanel Orientation="Vertical">
                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <TextBlock Text="Descrição" FontWeight="Bold" Width="95" VerticalAlignment="Center"/>
                                        <TextBox Width="425" MaxLength="50" Text="{Binding Path=Entidade.DetalheGarantia.DescricaoGarantia, Mode=TwoWay}" />
                                    </StackPanel>
                                    <StackPanel Orientation="Horizontal" Margin="5,1">
                                        <CheckBox Content="Garantia Formalizada" VerticalAlignment="Center" Margin="94,0,0,0" 
                                              IsChecked="{Binding Path=Entidade.DetalheGarantia.Formalizada, Mode=TwoWay}"/>
                                        <CheckBox Content="Sobrepor a Garantia Automática" VerticalAlignment="Center" Margin="15,0,0,0" 
                                              IsChecked="{Binding Path=Entidade.DetalheGarantia.SobrepoeAutomatica, Mode=TwoWay}"/>
                                    </StackPanel>
                                </StackPanel>
                            </Border>
                            <StackPanel Orientation="Horizontal">
                                <Border CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="#FF5A7194" Background="White" Margin="0,2">
                                    <StackPanel Orientation="Vertical">
                                        <Grid Background="White" HorizontalAlignment="Left" Margin="10,-8,0,2">
                                            <TextBlock Text="Ações" FontSize="11" Margin="5,0"/>
                                        </Grid>

                                        <StackPanel Orientation="Horizontal" Margin="5,1">
                                            <TextBlock Text="Codigo da Ação" Width="95" VerticalAlignment="Center"/>
                                            <TextBox Width="130" MaxLength="20" Text="{Binding Path=Entidade.DetalheGarantia.CodigoAcao, Mode=TwoWay}"/>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal" Margin="5,1">
                                            <TextBlock Text="Codigo da Bolsa" Width="95" VerticalAlignment="Center"/>
                                            <TextBox Width="130" MaxLength="20" Text="{Binding Path=Entidade.DetalheGarantia.CodigoBolsa, Mode=TwoWay}"/>
                                        </StackPanel>
                                        <StackPanel Orientation="Horizontal" Margin="5,1">
                                            <TextBlock Text="Avaliação" Width="95" VerticalAlignment="Center"/>
                                            <sdk:DatePicker Width="130" 
                                                        SelectedDate="{Binding Path=Entidade.DetalheGarantia.DataAvaliacao, Mode=TwoWay, Converter={StaticResource DateTimeConverter}}"/>
                                        </StackPanel>
                                    </StackPanel>
                                </Border>

                                <StackPanel Orientation="Vertical" Margin="5,0,0,0">
                                    <Border CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="#FF5A7194" Background="White" Margin="0,2" Padding="0,0,0,4">
                                        <StackPanel Orientation="Vertical">
                                            <Grid Background="White" HorizontalAlignment="Left" Margin="10,-8,0,2">
                                                <TextBlock Text="Vencimento" FontSize="11" Margin="5,0"/>
                                            </Grid>
                                            <StackPanel Orientation="Horizontal" Margin="5,1">
                                                <RadioButton GroupName="Vencimento" Content="Na operação" VerticalAlignment="Center" IsChecked="{Binding VencimentoNaOperacao}" Width="130" />
                                                <RadioButton x:Name="rdbVencNaData" GroupName="Vencimento" Content="" VerticalAlignment="Center"  />
                                                <sdk:DatePicker IsEnabled="{Binding ElementName=rdbVencNaData, Path=IsChecked}"
                                                            SelectedDate="{Binding Path=Entidade.DetalheGarantia.DataVencimento, Mode=TwoWay, Converter={StaticResource DateTimeConverter}}"/>
                                            </StackPanel>
                                        </StackPanel>
                                    </Border>

                                    <Border CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="#FF5A7194" Background="White" Margin="0,8,0,2" Padding="0,0,0,3">
                                        <StackPanel Orientation="Vertical">
                                            <Grid Background="White" HorizontalAlignment="Left" Margin="10,-8,0,2">
                                                <TextBlock Text="Incidência (%)" FontSize="11" Margin="5,0"/>
                                            </Grid>
                                            <StackPanel Orientation="Horizontal" Margin="5,1">
                                                <toolkit:NumericUpDown Height="22" Width="50" Margin="0,0,3,0" Value="{Binding DetalheGarantia.PercentualIncidencia, Mode=TwoWay}"/>
                                                <ComboBox Height="22" Width="225" 
                                                      ItemsSource="{Binding Path=ListaIncidencia}"                                                      
                                                      SelectedValue="{Binding Path=Entidade.IdMotivoIncidencia, Mode=TwoWay}"
                                                      SelectedValuePath="Codigo">
                                                    <ComboBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <StackPanel Orientation="Vertical">
                                                                <TextBlock Text="{Binding Path=Descricao, Mode=TwoWay}" />
                                                                <TextBlock Text="{Binding Path=Codigo, Mode=TwoWay}" 
                                                                       FontSize="9" Foreground="Red" Margin="0,0,30,0" HorizontalAlignment="Right" />
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </ComboBox.ItemTemplate>
                                                </ComboBox>
                                            </StackPanel>
                                        </StackPanel>
                                    </Border>
                                </StackPanel>

                            </StackPanel>

                            <Border CornerRadius="5,5,5,5" BorderThickness="1" BorderBrush="#FF5A7194" Background="White" Margin="0,8,0,2" Padding="0,0,0,3">
                                <StackPanel Orientation="Vertical">
                                    <Grid Background="White" HorizontalAlignment="Left" Margin="10,-8,0,2">
                                        <TextBlock Text="Garantidores" FontSize="11" Margin="5,0"/>
                                    </Grid>

                                    <StackPanel Orientation="Horizontal" Margin="5,2">
                                        <TextBlock Text="Garantidor" Width="95" VerticalAlignment="Center" />
                                        <sdk:AutoCompleteBox Width="300" />

                                        <Button Height="22" Width="22" Margin="2,0,0,0" Command="{Binding DetalheGarantidores.CommandAdd}">
                                            <Image Source="{StaticResource IconeAdicionar}" Height="16" Width="16" />
                                        </Button>
                                        <!--<Button Height="22" Width="22" Margin="2,0,0,0" Command="{Binding DetalheGarantidores.CommandRemove}">
                                        <Image Source="/ibba.src.noriskbo;component/Images/onebit_33.png" Height="16" Width="16" />
                                    </Button>-->

                                    </StackPanel>

                                    <sdk:DataGrid x:Name="dataGridGarantidor" Margin="5,2" Height="168" 
                                              AutoGenerateColumns="False" 
                                              HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
                                              ItemsSource="{Binding DetalheGarantidores.Colecao}"
                                              SelectedItem="{Binding DetalheGarantidores.Item, Mode=TwoWay}">
                                        <sdk:DataGrid.Columns>
                                            <sdk:DataGridTextColumn Header="Id" Binding="{Binding IdPessoa}" Width="1" IsReadOnly="True" Visibility="Collapsed" />
                                            <sdk:DataGridTextColumn Header="IdGarantia" Binding="{Binding IdGarantia}" Width="150" IsReadOnly="True" Visibility="Collapsed" />
                                            <sdk:DataGridTextColumn Header="IdGarantidor" Binding="{Binding IdGarantidor}" Width="150" IsReadOnly="True" Visibility="Collapsed" />
                                            <sdk:DataGridTextColumn Header="Nome" Binding="{Binding Nome}" Width="215" IsReadOnly="True" />
                                            <sdk:DataGridTextColumn Header="CPF / CNPJ" Binding="{Binding CpfCnpj}" Width="135" IsReadOnly="True" />
                                            <sdk:DataGridTextColumn Header="Pessoa" Binding="{Binding TipoPessoa}" Width="80" IsReadOnly="True" />
                                            <sdk:DataGridTextColumn Header="Perc.%" Binding="{Binding PercentualGarantidor}" Width="60"/>
                                            <sdk:DataGridTemplateColumn>
                                                <sdk:DataGridTemplateColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <Button x:Name="btnExcluirGarantidor" Command="{Binding DetalheGarantidores.CommandRemove}">
                                                            <Image Source="{StaticResource IconeRemover}" Width="16" Height="16" />
                                                        </Button>
                                                    </DataTemplate>
                                                </sdk:DataGridTemplateColumn.CellTemplate>
                                            </sdk:DataGridTemplateColumn>
                                        </sdk:DataGrid.Columns>
                                    </sdk:DataGrid>
                                </StackPanel>
                            </Border>
                        </StackPanel>
                    </Grid>
                </ContentControl>
            </Grid>
        </toolkit:BusyIndicator>
    </Grid>

</controls:ChildWindow>